package com.chebaohui.iqs.service.impl.deal.libao.util;

import com.alibaba.fastjson.JSONObject;
import com.chebaohui.iqs.config.CompanyValue;
import com.chebaohui.iqs.entity.req.CarPermit;
import com.chebaohui.iqs.service.impl.deal.util.StringUtil;

/**
 * 利宝确认投保请求参数
 * 
 * @author xielonghai
 *
 */
public class ConfirmParamtenGet {

	/** 配送信息 */
	private JSONObject tdistributionDto;
	/** 车主信息 */
	private JSONObject tprptCarOwnerDto;
	/** 投保人信息 */
	private JSONObject tprptApplicantDto;
	/** 被保险人信息 **/
	private JSONObject tprptInsuredDto;
	// 邮箱
	private String email = "260951277@qq.com";

	private CarPermit carPermit;

	public ConfirmParamtenGet(CarPermit carPermit) {
		this.carPermit = carPermit;
		this.tdistributionDto = new JSONObject();
		this.tprptCarOwnerDto = new JSONObject();
		this.tprptApplicantDto = new JSONObject();
		this.tprptInsuredDto = new JSONObject();
	}

	/** 配送信息 */
	public JSONObject getTdistributionDto() {
		if (!tdistributionDto.isEmpty())
			return tdistributionDto;
		tdistributionDto.put("name", carPermit.getDispatch().getName());// 客户名称
		tdistributionDto.put("cellPhoneNo", carPermit.getDispatch().getPhone());// 联系电话
		tdistributionDto.put("address", carPermit.getDispatch().getAddress());// 通信地址
		if (StringUtil.isNulls(carPermit.getDispatch().getEmail()))
			tdistributionDto.put("email", email);// 电子邮件
		else
			tdistributionDto.put("email", carPermit.getDispatch().getEmail());// 电子邮件

		tdistributionDto.put("callbackUrl", CompanyValue.PATH + "/price/libao/delivery");// 配送回调地址
		return tdistributionDto;
	}

	/** 车主信息 */
	public JSONObject getTprptCarOwnerDto() {
		if (!tprptCarOwnerDto.isEmpty())
			return tprptCarOwnerDto;

		tprptCarOwnerDto.put("name", carPermit.getOwner().getName());// 客户名称
		tprptCarOwnerDto.put("natureOfRole", "1");// 客户类型
		tprptCarOwnerDto.put("idType", "01");// 证件类型
		tprptCarOwnerDto.put("idNo", carPermit.getOwner().getIdCard());// 证件号码

		if (StringUtil.isNulls(carPermit.getOwner().getPhone()))
			tprptCarOwnerDto.put("cellPhoneNo", carPermit.getDispatch().getPhone());// 联系电话
		else
			tprptCarOwnerDto.put("cellPhoneNo", carPermit.getOwner().getPhone());// 联系电话

		if (StringUtil.isNulls(carPermit.getOwner().getAddress()))
			tprptCarOwnerDto.put("adress", carPermit.getDispatch().getAddress());// 通信地址
		else
			tprptCarOwnerDto.put("adress", carPermit.getOwner().getAddress());// 通信地址

		if (StringUtil.isNulls(carPermit.getOwner().getEmail()))
			tprptCarOwnerDto.put("email", email);// 电子邮件
		else
			tprptCarOwnerDto.put("email", carPermit.getOwner().getEmail());// 电子邮件

		return tprptCarOwnerDto;
	}

	/** 投保人信息 */
	public JSONObject getTprptApplicantDto() {
		if (!tprptApplicantDto.isEmpty())
			return tprptApplicantDto;

		tprptApplicantDto.put("name", carPermit.getApplicant().getName());// 客户名称
		tprptApplicantDto.put("idType", "01");// 证件类型
		tprptApplicantDto.put("idNo", carPermit.getApplicant().getIdCard());// 证件号码
		tprptApplicantDto.put("cellPhoneNo", carPermit.getApplicant().getPhone());// 联系电话
		tprptApplicantDto.put("adress", carPermit.getApplicant().getAddress());// 通信地址

		if (StringUtil.isNulls(carPermit.getApplicant().getEmail()))
			tprptApplicantDto.put("email", email);// 电子邮件
		else
			tprptApplicantDto.put("email", carPermit.getApplicant().getEmail());// 电子邮件

		return tprptApplicantDto;
	}

	/** 被保险人信息 **/
	public JSONObject getTprptInsuredDto() {
		if (!tprptInsuredDto.isEmpty())
			return tprptInsuredDto;

		tprptInsuredDto.put("name", carPermit.getInsured().getName());// 客户名称
		tprptInsuredDto.put("idType", "01");// 证件类型

		tprptInsuredDto.put("idNo", carPermit.getInsured().getIdCard());// 证件号码
		tprptInsuredDto.put("cellPhoneNo", carPermit.getInsured().getPhone());// 联系电话

		if (StringUtil.isNulls(carPermit.getInsured().getAddress()))
			tprptInsuredDto.put("adress", carPermit.getApplicant().getAddress());// 通信地址
		else
			tprptInsuredDto.put("adress", carPermit.getInsured().getAddress());// 通信地址

		if (StringUtil.isNulls(carPermit.getInsured().getEmail()))
			tprptInsuredDto.put("email", email);// 电子邮件
		else
			tprptInsuredDto.put("email", carPermit.getInsured().getEmail());// 电子邮件

		return tprptInsuredDto;
	}
}
